package cn.txy.system.service.impl;

import cn.txy.base.service.impl.BaseServiceImpl;
import cn.txy.system.domain.Role;
import cn.txy.system.mapper.RoleMapper;
import cn.txy.system.query.RoleQuery;
import cn.txy.system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> queryPage(RoleQuery roleQuery) {
        return roleMapper.queryPage(roleQuery);
    }

    @Override
    public void add(Role role) {
        Role r = roleMapper.findRoleByRole(role);
        if(r==null){
            roleMapper.add(role);
        }else {
            throw new RuntimeException(role.getSn()+"该角色编码已存在");
        }
    }

    @Override
    public void update(Role role) {
        Role r = roleMapper.findRoleByRole(role);
        if(r==null){
            super.update(role);
        }else {
            throw new RuntimeException(role.getSn()+"该角色编码已存在");
        }
    }
}
